package com.yanyq.message.m1;

import java.util.concurrent.TimeUnit;

/**
 * 消息的发布者
 *  用于对指定路径的增删改
 */
public class Publisher implements Runnable {
    private String[] paths;
    private String[] datas;
    private int[] operates;

    public Publisher(String[] paths,String[] datas,int[] operates){
        this.paths = paths;
        this.datas = datas;
        this.operates = operates;
    }

    @Override
    public void run(){
        ZkUtil zkUtil = new ZkUtil();
        int count = datas.length;
        for(int i = 0;i < count; i++){
            try {
                TimeUnit.SECONDS.sleep(2);
            }catch (InterruptedException e){
                e.printStackTrace();
            }
            zkUtil.operate(paths[i],datas[i],operates[i]);
            System.out.println("消息发布者["+Thread.currentThread().getName()+"],path:"+paths[i]+",data:"+datas[i]+",operate:"+operates[i]);
        }
    }
}
